# zstandard.cmake
# 本文件包含着从外部导入 zstandard 所需要的信息

SET(ZSTANDARD_SOURCES_DIR "${LIB_SOURCE_DIR}/extern_rocksdb" CACHE PATH "Path to bzip2 sources")
SET(ZSTANDARD_INCLUDE_DIR "${LIB_INCLUDE_DIR}" CACHE PATH "zstandard include directory." FORCE)
SET(ZSTANDARD_LIBRARIES "${LIB_INSTALL_DIR}/libzstandard.a" CACHE FILEPATH "zstandard include directory." FORCE)

ExternalProject_Add(
        extern_zstandard
        GIT_REPOSITORY https://github.com/facebook/zstd.git
        URL https://github.com/facebook/zstd/releases/download/v1.5.6/zstd-1.5.6.tar.gz
        CMAKE_ARGS
        -DCMAKE_INSTALL_PREFIX=${LIB_INSTALL_PREFIX}
        -DCMAKE_INSTALL_LIBDIR=${CMAKE_INSTALL_LIBDIR}
        -DCMAKE_BUILD_TYPE=${LIB_BUILD_TYPE}
        BUILD_COMMAND make
)

ADD_LIBRARY(zstandard STATIC IMPORTED GLOBAL)
SET_PROPERTY(TARGET zlib PROPERTY IMPORTED_LOCATION ${ROCKSDB_LIBRARIES})
ADD_DEPENDENCIES(zstandard extern_bzip2)